package com.app.micaihu.view.main.game.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.app.AppApplication;
import com.app.micaihu.bean.game.GameRelated;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.image.LoadImageUtils;
import com.facebook.drawee.generic.RoundingParams;

/**
 * Created by Guo on 2017/3/14.
 * 相关游戏的自定义view
 */

public class RelatedGameView extends LinearLayout {

    private Context context;
    private GameRelated gameRelated;
    private int position;

    public RelatedGameView(Context context, GameRelated gameRelated, int position) {
        super(context);
        this.context = context;
        this.gameRelated = gameRelated;
        this.position = position;
        init();
    }

    public RelatedGameView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public RelatedGameView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();

    }


    /**
     * 初始化 视图
     */
    private void init() {
        inflate(context, R.layout.view_relatedgame, this);
        CustomImageView civGamePic = (CustomImageView) findViewById(R.id.civ_gamepic);
        TextView tvGameTitle = (TextView) findViewById(R.id.tv_game_title);
        TextView tvGameType = (TextView) findViewById(R.id.tv_gametype);
        TextView tvGameScroe = (TextView) findViewById(R.id.tv_game_scroe);
        View placeHolder = findViewById(R.id.view_placehold);

        if (position == 0) {
            placeHolder.setVisibility(View.VISIBLE);
        } else {
            placeHolder.setVisibility(View.GONE);
        }
        if (this.gameRelated == null) {
            setVisibility(View.GONE);
        } else {
            setVisibility(View.VISIBLE);
            LoadImageUtils.getInstance().loadImage(civGamePic, this.gameRelated.getAppLogo());
            civGamePic.getHierarchy().setRoundingParams(new RoundingParams().setCornersRadius(40.0f));
            tvGameScroe.setText(this.gameRelated.getGradeScore());
            tvGameTitle.setText(this.gameRelated.getArticleTitle());
            tvGameType.setText(this.gameRelated.getAppType());
            this.setTag(this.gameRelated.getArticleId());
            this.setId(R.id.relatedview);
        }
    }
}
